import 'package:hrf_app/common/extension/ex_visibility.dart';
import 'package:hrf_app/common/values/svgs.dart';
import 'package:hrf_app/common/widgets/text_input_edit.dart';
import 'package:hrf_app/common/widgets/text_input_image_edit.dart';
import 'package:hrf_app/common/widgets/text_input_multiple_edit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'index.dart';

class MaterialDetailPage extends GetView<MaterialDetailPageController> {
  const MaterialDetailPage({super.key});

  // 主视图
  Widget _buildView() {
    return ListView(
      children: [
        TextInputEdit(
          labelText: "名称:",
          text: controller.materialModel.name ?? "",
        ),
        TDDivider(),
        TextInputEdit(
          labelText: "编码:",
          text: controller.materialModel.code ?? "",
        ),
        TDDivider(),
        TextInputEdit(
          labelText: "备注:",
          text: controller.materialModel.remark,
        ),
        TDDivider(),
        TextInputEdit(
          labelText: "创建人:",
          text: controller.materialModel.creatorName,
        ),
        TDDivider(),
        TextInputEdit(
          labelText: "创建时间:",
          text: controller.materialModel.createTime,
        ),
        TDDivider(),
        TextInputImageEdit(
          labelText: "附件:",
          uploadFileModelList: controller.uploadFileModelList,
          delCallBack: (index) {
            controller.delImage(index);
          },
          addCallBack: (dynamic param) {
            // 弹出底部弹窗选择相机或相册
            Get.bottomSheet(
              Container(
                height: 150,
                alignment: Alignment.center,
                color: Colors.white,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    ListTile(
                      leading: const Icon(Icons.camera),
                      title: const Text("相机"),
                      onTap: () {
                        controller.selectPhoto(ImageSource.camera);
                        Get.back(); // 关闭底部弹窗
                      },
                    ),
                    ListTile(
                      leading: const Icon(Icons.photo_library),
                      title: const Text("相册"),
                      onTap: () {
                        controller.selectMultiImage();
                        Get.back(); // 关闭底部弹窗
                      },
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ],
    );
  }


  @override
  Widget build(BuildContext context) {
    return GetBuilder<MaterialDetailPageController>(
      init: MaterialDetailPageController(),
      id: "materialDetailPage",
      builder: (_) {
        return Scaffold(
            appBar: AppBar(
              title: const Text("配件详情"),
            ),
            body: SafeArea(
                child: Column(children: [
                  Expanded(child: _buildView()),
                ])));
      },
    );
  }
}
